//
//  CustomGridCell.m
//  DemoMeshtiles
//
//  Created by MAC on 7/18/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CustomGridCell.h"
#import <QuartzCore/QuartzCore.h>

@implementation CustomGridCell
@synthesize egoCellArray;
@synthesize cellDataArray;
@synthesize gridViewController;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        egoCellArray=[[NSMutableArray alloc] initWithCapacity:4];
        for (int i=0;i<4;i++) {
            EGOImageButton *egoView=nil;
            if (i%2==0) {
                egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"224.png"]];

            } else {
                egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"255.png"]];

            }
//            EGOImageButton *egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"thumb1.jpeg"]];
       
            
            egoView.frame=CGRectMake(80*i+3, 5, 65, 65);
            egoView.layer.masksToBounds=YES;
            egoView.layer.cornerRadius=15.0f;
                                                                                          
            [self.contentView addSubview:egoView];    
             [egoCellArray addObject:egoView];  
        }
        cellDataArray=[[NSMutableArray alloc] init];    
       
    }
    return self;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier withStyle:(NSInteger)row
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        egoCellArray=[[NSMutableArray alloc] initWithCapacity:4];
        for (int i=0;i<4;i++) {
            EGOImageButton *egoView=nil;
            if(row%2==0) {
                if (i%2==0) {
                    egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"224.png"]];
                    
                } else {
                    egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"255.png"]];
                
                }
            } else {
                if (i%2==0) {
                    egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"255.png"]];
                    
                } else {
                    egoView=[[EGOImageButton alloc] initWithPlaceholderImage:[UIImage imageNamed:@"224.png"]];
                    
                }
            }
      
           [egoView addTarget:gridViewController action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
            
            egoView.frame=CGRectMake(80*i+3, 5, 65, 65);
            egoView.layer.masksToBounds=YES;
            egoView.layer.cornerRadius=15.0f;
            
            
            [self.contentView addSubview:egoView];    
            [egoCellArray addObject:egoView];  
        }
        cellDataArray=[[NSMutableArray alloc] init];    
        
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}
-(void)setCellsData:(NSMutableArray *)cellsData {
    [self.cellDataArray removeAllObjects];
    [cellDataArray addObjectsFromArray:cellsData];
    
    for (int i=0;i<[cellDataArray count];i++) {
        NSDictionary *photoItem=(NSDictionary*)[cellDataArray objectAtIndex:i];
        //set image for cell
        EGOImageButton *egoButton=(EGOImageButton*)[egoCellArray objectAtIndex:i];
        NSString *urlString=[photoItem objectForKey:@"url_thumb"];
        [egoButton setImageURL:[NSURL URLWithString:urlString]];
        [egoButton setPhotoId:[photoItem objectForKey:@"photo_id"]];
        
    }
}


@end
